<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="statics/layui/css/layui.css" rel="stylesheet">
</head>
<%--
   AJAX:1:异步请求，局部刷新：
   RBAC:权限管理
--%>
<script src="statics/layui/layui.js"></script>
<script src="statics/js/jquery-3.7.1.min.js"></script>
<script>
     $(function () {
          $("form").submit(function () {
              //获取表单元素的值
              var uname=$("#name").val()
              var upassword=$("#upassword").val()

              //需要验证
              if(uname =="" || uname == undefined){
                  alert("用户名不能为空");
                  return;
              }

              if(upassword =="" || upassword == undefined){
                  alert("密码不能为空");
                  return;
              }
              $.ajax({
                  url:"/user",
                  data:{
                      "type":"tologin",
                      "uname":uname,
                      "upassword":upassword
                  },
                  type:"GET",
                  dataType:"json", //跨平台的数据交互格式
                  success:function (res) {
                       if(res.state==200){
                           alert(res.msg);
                           location.href="/menus?type=getMenus";
                       }else {
                           alert(res.msg);
                       }
                  },
                  error:function () {

                  }

              })
          })

     })
</script>

<body>
<div>
    <form action="javaScript:void (0)" method="post">
       用户名：<input id="name" type="text" name="uname" value="">
       密码： <input id="upassword"  type="text" name="upassword" value="">
        <input type="submit" value="登录">
    </form>
   <%-- <a href="/login?uname=lisi&&upassword=123">登录</a>--%>
    <a href="/addUser">新增</a>
    <a href="/delUser?id=1">删除</a>
</div>
</body>
</html>